package com.gkusbsdk;

public class GKUSBSDK {
	
	public interface CallBack{
		public void cb_stream(long hUSBDevice, byte[] data, int length, int width, int height, int time);
	}

	public static CallBack getCallback() {
		return __cb;
	}

	public static CallBack __cb;
	public static void setCallback(CallBack cb){
		__cb = cb;
	}
	
	// 检索USB设备 Object为USB
	public native static int GKUSB_SearchVideoNodeCams(Object[] usbArray);
	
	// 获取SDK版本 
	public native static int GKUSB_GetUSBSDKVersion();
	
	// 创建USB设备
	public native static long GKUSB_CreateVideoNodeCam(Object usb);

	public native static long GKUSB_CreateVideoVsUvcCam(String usb);
	public native static long GKUSB_CreateBusNodeCam(int fd, int vid, int pid, int busnum, int devnum, String usbfs); 
	public native static int GKUSB_Destroy(long hUSBDevice);
	
	// 设置协议类型 type参考 PROTOCOL_TYPE  非特殊情况，此处填TYPE_NEW
	public native static int GKUSB_SetProtocol(long hUSBDevice, int type);

	// 获取设备在线状态
	public native static int GKUSB_GetOnlineStatus(long hUSBDevice);
	
	// 开关预览
	public native static long GKUSB_OpenStream(long hUSBDevice, Object objFormat, Object objResolution);
	public native static int GKUSB_CloseStream(long hUSBDevice);
	
	// 获取当前状态 支持STATUS_CONTROL所有指令
	public native static int GKUSB_GetCurrentStatus(long hUSBDevice, int status_ctrl);
	
	// 搜索所有此类型文件信息 type:0:循环视频  1:紧急视频 2:照片
	public native static int GKUSB_SearchFile(long hUSBDevice, int type, Object[] fileInfoArray);
	public native static int GKUSB_SearchFileName(long hUSBDevice, int type, Object[] filenameArray); //Object:GKUSBFile
	public native static int GKUSB_SearchFileDate(long hUSBDevice, int type, Object[] dateArray);
	
	// 获取当前文件信息 返回GKUSBFileInfo
	public native static Object GKUSB_GetFileInfo(long hUSBDevice, byte[] name);
	public native static Object GKUSB_GetFileInfoEx(long hUSBDevice, int type, byte[] name);
	
	// 视频和照片控制 GKUSBFileInfo  type:0:循环视频  1:紧急视频 2:照片  control: VIDEO_FILE_CONTROL&PHOTO_FILE_CONTROL
	public native static int GKUSB_FileControl(long hUSBDevice, int type, int control, byte[] name);
	
	// 获取缩略图数据 照片:jpg图片 视频:一帧h264数据
	public native static int GKUSB_GetSmallPicture(long hUSBDevice, int type, byte[] name, Object obj);
	
	// 获取当前回放时长
	public native static int GKUSB_GetCurrentPlaybackTime(long hUSBDevice);
	
	// 获取/设置录像状态
	public native static int GKUSB_GetRecordStatus(long hUSBDevice);
	public native static int GKUSB_SetRecordStatus(long hUSBDevice, int open);
	
	// 参数配置
	public native static int GKUSB_SetParam(long hUSBDevice, int command, Object object);
	public native static int GKUSB_GetParam(long hUSBDevice, int command, Object object);
	
	// 获取错误码
	public native static int GKUSB_GetLastErr(long hUSBDevice);
	// 设置摄像头
	public native static int GKUSB_SetLiveScreenStatus(long hUSBDevice, int status);

	public native static int GKUSB_GetLiveScreenStatus(long hUSBDevice);

	
	// 视频数据回调 
	public static void callback_stream(int hUSBDevice, byte[] data, int length, int width, int height, int time/*仅回放使用时间*/){
		
		if(__cb != null){
			__cb.cb_stream(hUSBDevice, data, length, width, height,time);
			
		}
		
		//Log.i("gkusb", ""+data[0]+" "+data[1]+" "+data[2]+" "+data[3]+" time:"+time);
	}
	
	static{
		System.loadLibrary("decoder");
		System.loadLibrary("usb");
		System.loadLibrary("uvc");
		System.loadLibrary("gkusbsdk");
	}
}
